package cn.yangphere.bean;

import javax.persistence.Entity;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;


public class AnnotationUtils {
	
	/**
	 * 获取实体的名称
	 * @param <T>
	 * @param entityClass 实体类
	 * @return
	 */
	public static <T> String getEntityName(Class<T> entityClass){
		String entityName = entityClass.getSimpleName();
		
		Entity entity = entityClass.getAnnotation(Entity.class);
		if(StringUtils.isNotEmpty(entity.name())){
			entityName = entity.name();
		}
		return entityName;
	}
	
	/**
	 * 获取action中Controller注解的value值
	 * @param <T>
	 * @param clazz
	 * @return
	 */
	public static <T> String getActionControllerUrl(Class<T> clazz){
		String actionUrl = "#";
		Controller controller = (Controller) clazz.getAnnotation(Controller.class);
		if(StringUtils.isNotEmpty(controller.value())){
			actionUrl = controller.value();
		}
		return actionUrl;
	}
}
